//
//  IncomeTopTableViewCell.m
//  Cat
//
//  Created by lushitong on 2018/12/5.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "IncomeTopTableViewCell.h"
#import "EarnModel.h"

@interface IncomeTopTableViewCell()

@property (nonatomic, strong) UIImageView *operView;
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UILabel *moneyNumberLabel;
@property (nonatomic, strong) UILabel *totalLabel;

@property (nonatomic, strong) UILabel *thisMonthLabel;

@property (nonatomic, strong) UIView *thisOperView;
@property (nonatomic, strong) UILabel *thisMonthELabel;
@property (nonatomic, strong) UILabel *thisMonthInfoLabel;
@property (nonatomic, strong) UILabel *successNumberLabel;
@property (nonatomic, strong) UILabel *successInfoLabel;

@property (nonatomic, strong) UIView *nextOperView;
@property (nonatomic, strong) UILabel *lastMoneyLabel;
@property (nonatomic, strong) UILabel *lastGetLabel;
@property (nonatomic, strong) UILabel *lastInfoLabel;
@property (nonatomic, strong) UILabel *lastELabel;
@property (nonatomic, strong) UILabel *lastEInfoLabel;
@property (nonatomic, strong) UILabel *lastSuccessNumLabel;
@property (nonatomic, strong) UILabel *lastInfoSuccessLabel;

@end

@implementation IncomeTopTableViewCell

- (void)setCellModelData:(id)cellModelData {
	if ([cellModelData isKindOfClass:[EarnModel class]]) {
		EarnModel *mode = (EarnModel *)cellModelData;
		self.moneyNumberLabel.text = [NSString stringWithFormat:@"￥%@",mode.balance];
		self.totalLabel.text = [NSString stringWithFormat:@"累计已结算收益 ￥%@",mode.fundoutAmount];
		self.thisMonthInfoLabel.text = [NSString stringWithFormat:@"￥%@",mode.mounthExpectAmount];
		self.successInfoLabel.text = [mode.monthNum.stringValue length] > 0 ? mode.monthNum.stringValue : @"0";
		self.lastInfoLabel.text = [NSString stringWithFormat:@"￥%@",mode.lastRealAmount];
		self.lastEInfoLabel.text = [NSString stringWithFormat:@"￥%@",mode.lastExpectAmount];
		self.lastInfoSuccessLabel.text = mode.lastNum.stringValue;
	}
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	if (self) {
		self.cellSeparatorStyle = QKUITableViewCellSeparatorStyleNone;
		self.selectionStyle = UITableViewCellSelectionStyleNone;
		[self loadSubviews];
	}
	return self;
}

- (void)loadSubviews {
	[self.contentView addSubviews:@[self.operView,self.thisMonthLabel,self.thisOperView,self.nextOperView,self.lastMoneyLabel]];
	[self.operView addSubviews:@[self.moneyLabel,self.moneyNumberLabel,self.totalLabel]];
	[self.thisOperView addSubviews:@[self.thisMonthELabel,self.thisMonthInfoLabel,self.successNumberLabel,self.successInfoLabel]];
	[self.nextOperView addSubviews:@[self.lastGetLabel,self.lastInfoLabel,self.lastELabel,self.lastEInfoLabel,self.lastSuccessNumLabel,self.lastInfoSuccessLabel]];
	
	[self.operView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.contentView.mas_left).offset(kQKFitModuleDecimal(16));
		make.right.equalTo(self.contentView.mas_right).offset(-kQKFitModuleDecimal(16));
		make.top.equalTo(self.contentView.mas_top).offset(kQKFitModuleDecimal(16));
		make.height.equalTo(@(kQKFitModuleDecimal(118)));
	}];
	
	[self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.operView.centerX);
		make.top.equalTo(self.operView.mas_top).offset(kQKFitModuleDecimal(16));
		make.height.equalTo(@(kQKFitModuleDecimal(10)));
	}];
	
	[self.moneyNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.moneyLabel.mas_centerX);
		make.top.equalTo(self.moneyLabel.mas_bottom).offset(kQKFitModuleDecimal(9));
		make.height.equalTo(@(kQKFitModuleDecimal(24)));
	}];
	
	[self.totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.moneyLabel.mas_centerX);
		make.top.equalTo(self.moneyNumberLabel.mas_bottom).offset(kQKFitModuleDecimal(7));
	}];
	
	[self.thisMonthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.operView.mas_left);
		make.top.equalTo(self.operView.mas_bottom).offset(kQKFitModuleDecimal(16));
	}];
	
	[self.thisOperView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.operView.mas_left);
		make.right.equalTo(self.operView.mas_right);
		make.height.equalTo(@(kQKFitModuleDecimal(68)));
		make.top.equalTo(self.thisMonthLabel.mas_bottom).offset(kQKFitModuleDecimal(12));
	}];
	
	[self.thisMonthELabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.thisOperView.mas_left).offset(kQKFitModuleDecimal(26));
		make.top.equalTo(self.thisOperView.mas_top).offset(kQKFitModuleDecimal(15));
	}];
	
	[self.thisMonthInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.thisMonthELabel.mas_centerX);
		make.top.equalTo(self.thisMonthELabel.mas_bottom).offset(kQKFitModuleDecimal(7));
	}];
	
	[self.successNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.contentView.mas_centerX);
		make.top.equalTo(self.thisMonthELabel.mas_top);
	}];
	
	[self.successInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.successNumberLabel.mas_centerX);
		make.top.equalTo(self.successNumberLabel.mas_bottom).offset(kQKFitModuleDecimal(7));
	}];
	
	[self.lastMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.thisOperView.mas_left);
		make.top.equalTo(self.thisOperView.mas_bottom).offset(kQKFitModuleDecimal(16));
	}];
	
	[self.nextOperView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.and.right.equalTo(self.thisOperView);
		make.top.equalTo(self.lastMoneyLabel.mas_bottom).offset(kQKFitModuleDecimal(12));
		make.height.equalTo(@(kQKFitModuleDecimal(68)));
	}];
	
	[self.lastGetLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.nextOperView.mas_left).offset(kQKFitModuleDecimal(25));
		make.top.equalTo(self.nextOperView.mas_top).offset(kQKFitModuleDecimal(15));
	}];
	
	[self.lastInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.lastGetLabel.mas_centerX);
		make.top.equalTo(self.lastGetLabel.mas_bottom).offset(kQKFitModuleDecimal(7));
	}];

	[self.lastELabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.contentView.mas_centerX);
		make.top.equalTo(self.nextOperView.mas_top).offset(kQKFitModuleDecimal(15));
	}];
	
	[self.lastEInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerX.equalTo(self.lastELabel.mas_centerX);
		make.top.equalTo(self.lastELabel.mas_bottom).offset(kQKFitModuleDecimal(7));;
	}];
	
	[self.lastSuccessNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(self.lastGetLabel.mas_top);
		make.right.equalTo(self.contentView.mas_right).offset(-kQKFitModuleDecimal(37));
	}];
	
	[self.lastInfoSuccessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(self.lastSuccessNumLabel.mas_bottom).offset(kQKFitModuleDecimal(7));
		make.centerX.equalTo(self.lastSuccessNumLabel.mas_centerX);
	}];
}

#pragma mark----- lazy init -----

- (UIImageView *)operView {
	if (!_operView) {
		_operView = [[UIImageView alloc] init];
		_operView.image = [UIImage createImageWithSize:CGSizeMake(ScreenWidth - kQKFitModuleDecimal(16 * 2), kQKFitModuleDecimal(118)) gradientColors:@[COLOR_WITH_HEX(0x515359),COLOR_WITH_HEX(0x262628)] percentage:@[@(0),@(1)] gradientType:GradientFromTopToBottom];
		_operView.layer.cornerRadius = kQKFitModuleDecimal(6);
		_operView.layer.masksToBounds = YES;
	}
	return _operView;
}

- (UILabel *)moneyLabel {
	if (!_moneyLabel) {
		_moneyLabel = [UILabel labelWithText:@"我的余额" font:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0xCDC7C4)];
	}
	return _moneyLabel;
}

- (UILabel *)moneyNumberLabel {
	if (!_moneyNumberLabel) {
		_moneyNumberLabel = [UILabel labelWithText:@"￥00.00" font:[UIFont boldSystemFontOfSize:kQKFitFont(24)] textColor:COLOR_WITH_HEX(0xFFC236)];
	}
	return _moneyNumberLabel;
}

- (UILabel *)totalLabel {
	if (!_totalLabel) {
		_totalLabel = [UILabel labelWithText:@"累计已结算收益 ￥0.00" font:[UIFont systemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0xCDC7C4)];
	}
	return _totalLabel;
}

- (UILabel *)thisMonthLabel {
	if (!_thisMonthLabel) {
		_thisMonthLabel = [UILabel labelWithText:@"本月" font:[UIFont boldSystemFontOfSize:kQKFitFont(14)] textColor:COLOR_WITH_HEX(0x4A4A4A)];
	}
	return _thisMonthLabel;
}

- (UIView *)thisOperView {
	if (!_thisOperView) {
		_thisOperView = [[UIView alloc] init];
		_thisOperView.backgroundColor = COLOR_WITH_HEX(0xFAFAFA);
		_thisOperView.layer.cornerRadius = kQKFitModuleDecimal(3);
		_thisOperView.layer.masksToBounds = YES;
	}
	return _thisOperView;
}

- (UILabel *)thisMonthELabel {
	if (!_thisMonthELabel) {
		_thisMonthELabel = [UILabel labelWithText:@"本月收益预估" font:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0x57524F)];
	}
	return _thisMonthELabel;
}

- (UILabel *)thisMonthInfoLabel {
	if (!_thisMonthInfoLabel) {
		_thisMonthInfoLabel = [UILabel labelWithText:@"￥00.00" font:[UIFont boldSystemFontOfSize:kQKFitFont(18)] textColor:COLOR_WITH_HEX(0xFFC236)];
	}
	return _thisMonthInfoLabel;
}

- (UILabel *)successNumberLabel {
	if (!_successNumberLabel) {
		_successNumberLabel = [UILabel labelWithText:@"成功笔数" font:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0x57524F)];
	}
	return _successNumberLabel;
}


- (UILabel *)successInfoLabel {
	if (!_successInfoLabel) {
		_successInfoLabel = [UILabel labelWithText:@"0" font:[UIFont boldSystemFontOfSize:kQKFitFont(18)] textColor:COLOR_WITH_HEX(0xFFC236)];
	}
	return _successInfoLabel;
}

- (UIView *)nextOperView {
	if (!_nextOperView) {
		_nextOperView = [[UIView alloc] init];
		_nextOperView.backgroundColor = COLOR_WITH_HEX(0xFAFAFA);
		_nextOperView.layer.cornerRadius = kQKFitModuleDecimal(3);
		_nextOperView.layer.masksToBounds = YES;
	}
	return _nextOperView;
}

- (UILabel *)lastMoneyLabel {
	if (!_lastMoneyLabel) {
		_lastMoneyLabel = [UILabel labelWithText:@"上月" font:[UIFont boldSystemFontOfSize:kQKFitFont(14)] textColor:COLOR_WITH_HEX(0x4A4A4A)];
	}
	return _lastMoneyLabel;
}

- (UILabel *)lastGetLabel {
	if (!_lastGetLabel) {
		_lastGetLabel = [UILabel labelWithText:@"上月结算收益" font:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0x57524F)];
	}
	return _lastGetLabel;
}

- (UILabel *)lastInfoLabel {
	if (!_lastInfoLabel) {
		_lastInfoLabel =  [UILabel labelWithText:@"￥00.00" font:[UIFont boldSystemFontOfSize:kQKFitFont(18)] textColor:COLOR_WITH_HEX(0xFFC236)];
	}
	return _lastInfoLabel;
}

- (UILabel *)lastELabel {
	if (!_lastELabel) {
		_lastELabel = [UILabel labelWithText:@"上月预计收益" font:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0x57524F)];
	}
	return _lastELabel;
}

- (UILabel *)lastEInfoLabel {
	if (!_lastEInfoLabel) {
		_lastEInfoLabel = [UILabel labelWithText:@"￥00.00" font:[UIFont boldSystemFontOfSize:kQKFitFont(18)] textColor:COLOR_WITH_HEX(0xFFC236)];
	}
	return _lastEInfoLabel;
}

- (UILabel *)lastSuccessNumLabel {
	if (!_lastSuccessNumLabel) {
		_lastSuccessNumLabel = [UILabel labelWithText:@"成功笔数" font:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0x57524F)];
	}
	return _lastSuccessNumLabel;
}

- (UILabel *)lastInfoSuccessLabel {
	if (!_lastInfoSuccessLabel) {
		_lastInfoSuccessLabel = [UILabel labelWithText:@"0" font:[UIFont boldSystemFontOfSize:kQKFitFont(18)] textColor:COLOR_WITH_HEX(0xFFC236)];
	}
	return _lastInfoSuccessLabel;
}

@end
